import 'package:get/get.dart';
import 'package:ty_smart_watch/utils/Log.dart';
import 'package:ty_smart_watch/utils/db_util.dart';

class DeviceInDbController extends GetxController {
  late DbUtil _dbUtil;

  var deviceList = Rx<List<Map<String, dynamic>>>([]);

  @override
  void onInit() {
    super.onInit();
    Log.d("DeviceInDbController > onInit");
  }

  @override
  void onReady() async {
    super.onReady();
    Log.d("DeviceInDbController > onReady");

    _dbUtil = DbUtil();
    var tempList = await _dbUtil.getAllDevice();
    deviceList.value
      ..clear()
      ..addAll(tempList);
    deviceList.refresh();
  }

  @override
  void onClose() {
    super.onClose();
    Log.d("DeviceInDbController > onClose");
  }

  updateDbList(List<Map<String, dynamic>> list) {
    deviceList.value
      ..clear()
      ..addAll(list);
    deviceList.refresh();
  }
}
